using System;
using System.Collections.Generic;
using BitMango.Diagnostics;

namespace BitMango.MultiPlayer.GPGS
{
    public class MatchGPGS101 : MatchImplBase
    {
        protected override void OpenImpl(int _gameVariant, Action<bool> callback)
        {
        }

        protected override void CloseImpl(bool opponent)
        {
        }

        protected override void SendInternalImpl(byte cmd, object msg)
        {
        }

        private void OnAuthenticated(bool success)
        {
            Debugger.Log("MatchGPGS101.OnAuthenticated : " + success);
            Debugger.Assert(MatchImplBase.State == MatchImplBase.STATE.OPEN, "MatchGPGS101.OnAuthenticated state:" + MatchImplBase.State);
            {
                base.OnOpenInternal(success);
            }
        }

        public void OnRoomSetupProgress(float percent)
        {
            Debugger.Log("MatchGPGS101.OnRoomSetupProgress : " + percent);
        }

        public void OnRoomConnected(bool success)
        {
            Debugger.Log("MatchGPGS101.OnRoomConnected : " + success);
            if (MatchImplBase.State != MatchImplBase.STATE.OPEN)
            {
                return;
            }
            base.OnOpenInternal(success);
        }

        public void OnLeftRoom()
        {
            Debugger.Log("MatchGPGS101.OnLeftRoom");
            if (MatchImplBase.State != MatchImplBase.STATE.NONE)
            {
                Platform.SafeCallback<bool>(new Action<bool>(base.Close), false);
            }
        }

        public void OnPeersConnected(string[] participantIds)
        {
            Debugger.Log("MatchGPGS101.OnPeersConnected : " + participantIds.Length);
        }

        public void OnPeersDisconnected(string[] participantIds)
        {
            Debugger.Log("MatchGPGS101.OnPeersDisconnected : " + participantIds.Length);
            base.Close(true);
        }

        public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data)
        {
            byte b = data[0];
            object msg = MatchImplBase.ByteArrayToObject(data, 1);
            Debugger.Log(string.Concat(new object[]
            {
                "MatchGPGS101.OnRealTimeMessageReceived : cmd(",
                b,
                ") isReliable(",
                isReliable,
                ") senderId(",
                senderId,
                ") dateLen(",
                data.Length,
                ")"
            }));
            base.OnRecvInternal(b, msg);
        }

        private int gameVariant;
    }
}
